/**
 * 
 */
package jobs.poc.writables;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

import org.apache.hadoop.io.Text;
import org.apache.hadoop.io.Writable;
import org.apache.hadoop.io.WritableComparable;

/**
 * @author zvikadori
 *
 */
public class WordPairDecade implements WritableComparable<WordPairDecade> {
	private String firstWord;
	private String secondWord;
	private int decade;
	
	

	public String getFirstWord() {
		return firstWord;
	}

	public void setFirstWord(String firstWord) {
		this.firstWord = firstWord;
	}

	public String getSecondWord() {
		return secondWord;
	}

	public void setSecondWord(String secondWord) {
		this.secondWord = secondWord;
	}

	public int getDecade() {
		return decade;
	}

	public void setDecade(int decade) {
		this.decade = decade;
	}

	/* (non-Javadoc)
	 * @see org.apache.hadoop.io.Writable#readFields(java.io.DataInput)
	 */
	public void readFields(DataInput arg0) throws IOException {
		// TODO Auto-generated method stub
		firstWord = arg0.readUTF();
		secondWord = arg0.readUTF();
		decade = Integer.parseInt(arg0.readUTF());

	}

	/* (non-Javadoc)
	 * @see org.apache.hadoop.io.Writable#write(java.io.DataOutput)
	 */
	public void write(DataOutput arg0) throws IOException {
		arg0.writeUTF(firstWord);
		arg0.writeUTF(secondWord);
		arg0.writeUTF(Integer.toString(decade));
	}
	
	public String toString(){
		String ans = firstWord + " " + secondWord + " " + decade;
		return ans;
	}
	
	public static WordPairDecade fromString(Text line){
		WordPairDecade ans = null;
		String[] splits = line.toString().split(" ");
		if (splits.length == 3){
			ans = new WordPairDecade();
			ans.setFirstWord(splits[0]);
			ans.setSecondWord(splits[1]);
			ans.setDecade(Integer.parseInt(splits[2]));
		}
		return ans;
	}
	
	public static WordPairDecade createWordPairDecade(String firstWord, String secondWord, int decade){
		WordPairDecade ans = new WordPairDecade();
		ans.setFirstWord(firstWord);
		ans.setSecondWord(secondWord);
		ans.setDecade(decade);
		return ans;
		
	}

	public int compareTo(WordPairDecade o) {
		// TODO Auto-generated method stub
		return 0;
	}
	
	

}
